home *** CD-ROM | disk | FTP | other *** search
/ SGI Performance Co-Pilot 1.3 / SGI Performance Co-Pilot 1.3.iso / dist / pcp.idb / usr / pcp / bin / pmnsadd.z / pmnsadd
Text File  |  1997-04-03  |  2KB  |  91 lines

  1. #!/bin/sh
  2. # $Id: pmnsadd,v 2.1 1997/03/26 03:07:50 kenmcd Exp $
  3. #
  4. # Add a subtree of new names into the namespace in the current directory
  5.  
  6. exitsts=1
  7. tmp=/var/tmp/$$
  8. prog=`basename $0`
  9. trap "rm -f $tmp.*; exit \$exitsts" 0 1 2 3 15
  10.  
  11. _usage()
  12. {
  13.     echo "Usage: pmnsadd [-d] [-n namespace] file"
  14. }
  15.  
  16. namespace=${PMNS_DEFAULT-/var/pcp/pmns/root}
  17. dupok=""
  18. umask 22        # anything else is pretty silly
  19.  
  20. while getopts dn:\? c
  21. do
  22.     case $c
  23.     in
  24.     d)    dupok="-d"
  25.         ;;
  26.     n)    namespace=$OPTARG
  27.         ;;
  28.     \?)    _usage
  29.         exitsts=0
  30.         exit
  31.         ;;
  32.     esac
  33. done
  34. shift `expr $OPTIND - 1`
  35.  
  36. if [ $# -ne 1 ]
  37. then
  38.     _usage
  39.     exit
  40. fi
  41.  
  42. if [ ! -f $namespace ]
  43. then
  44.     echo "$prog: cannot find PMNS file \"$root\""
  45.     exit
  46. fi
  47.  
  48. if [ ! -w $namespace ]
  49. then
  50.     echo "$prog: cannot open PMNS file \"$root\" for writing"
  51.     exit
  52. fi
  53.  
  54. if [ ! -f $1 ]
  55. then
  56.     echo "$prog: cannot find input file \"$1\""
  57.     exit
  58. fi
  59.  
  60. # Find PMNS pathname for base of new subtree (subroot), construct upper
  61. # levels of PMNS as required and hand-off to pmnsmerge
  62. #
  63. subroot=`nawk <$1 'NF >= 2 && $2 == "\{" { print $1 ; exit }'`
  64.  
  65. echo 'root {' >$tmp.tmp
  66. path=""
  67. for name in `echo "$subroot" | tr '.' ' '`
  68. do
  69.     [ ! -z "$path" ] && echo "$path {" >>$tmp.tmp
  70.     echo "    $name" >>$tmp.tmp
  71.     echo "}" >>$tmp.tmp
  72.     if [ -z "$path" ]
  73.     then
  74.     path="$name"
  75.     else
  76.     path="$path.$name"
  77.     fi
  78. done
  79. cat $1 >>$tmp.tmp
  80.  
  81. /usr/pcp/bin/pmnsmerge $dupok $namespace $tmp.tmp $tmp.root
  82. exitsts=$?
  83.  
  84. if [ $exitsts = 0 ]
  85. then
  86.     cp $tmp.root $namespace
  87.     cp $tmp.root.bin $namespace.bin
  88. else
  89.     echo "$prog: No changes have been made to the PMNS file \"$namespace\""
  90. fi
  91.